/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package war2100.game.helper;

import org.newdawn.slick.GameContainer;
import org.newdawn.slick.geom.Vector2f;
import war2100.GameConstants;
import war2100.entity.Map;

/**
 *
 * @author efischer
 */
public class Vector2Helper 
{
	public static float getTargetAngle(Vector2f loc, Vector2f target) {
		Vector2f delta = target.sub(loc);
		return (float)Math.toDegrees(Math.atan2(delta.getY(), delta.getX())) + 90;
	}
	
	public static Vector2f getFieldSize()
	{
		int fieldWidth = GameConstants.tileXSize;
		int fieldHeight = GameConstants.tileYSize;

		if (fieldWidth > fieldHeight)
			fieldWidth = fieldHeight;
		else
			fieldHeight = fieldWidth;
		
		return new Vector2f(fieldWidth, fieldHeight);
	}
	
	public static Vector2f getOffset(Map map, GameContainer gc)
	{
		Vector2f fieldSize = getFieldSize();


		int offsetX = 0;
		int offsetY = 0;

		if(map.getxSize()*fieldSize.getX() < gc.getWidth())
			offsetX = (gc.getWidth() - map.getxSize()*(int)fieldSize.getX())/2;
		if(map.getySize()*fieldSize.getY() < gc.getHeight())
			offsetY = (gc.getHeight() - map.getySize()*(int)fieldSize.getY())/2;
		
		return new Vector2f(offsetX, offsetY);
	}
}
